// ActionScript file
package{
	import flash.net.SharedObject;
	
	import mx.formatters.DateFormatter;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	import web.OperateTip;
	public final  class Global{
		
		    public static var app:index;
		    public static var operateTip:OperateTip;
		    
           
			/**
			 * 是否是email
			 * */
			public static function isEmail(email:String):Boolean{
				
				var patten:RegExp= /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
				
					return patten.test(email);
				
			}
			
			/**
			 * 去除空格
			 * */
			public static function trim(str:String):String{
				
				
				return str= str.replace(/(\s)*/gi , "");
			}
			
			public static function dateToString(date:Date,format:String=null):String{
				
				 var fr:DateFormatter=new DateFormatter();
				 if(format==null){
				 	  fr.formatString="YYYY-MM-DD HH:NN:SS";
				 }else{
				 	  fr.formatString=format;
				 }
                  return fr.format(date);

			}
			
			/**
			 * 
			 * 转换登录状态
			 * */
			public static function loginResult(str:String):String{
				var result:String;
				switch (str){
					
					case "EMAIL_IS_NULL":result="Email为空";break;
					case "EMAIL_FORMAT_ERROR":result="Email格式错误";break;
					case "EMAIL_IS_ERROR":result="Email不存在";break;
					case "PASSWORD_IS_NULL":result="密码为空";break;
					case "PASSWORD_ERROR":result="密码错误";break;
					
				}
				
				return result;
			}
			
			public static function getUserId():String{
				return "12345699";
				var sharedObj:SharedObject=SharedObject.getLocal("USER");
				if(sharedObj.data.userId==undefined){
		
	          //登录
		      return "";
          	}else{
		 
		       return sharedObj.data.userId;
	         }
	         
			}
			//远程访问封装
		public static function getRemoteObject(s:String,showBusyCursor:Boolean=true,callback:Function=null):RemoteObject{
			
			var ro:RemoteObject=new RemoteObject(s);
			    ro.endpoint="messagebroker/amf";
			    ro.showBusyCursor=showBusyCursor;
			    ro.addEventListener(ResultEvent.RESULT,callback);
			
			return ro;
		}
		//倒计时
		public static function countdown(seconds:int):String{
			var str:String;
		    var h:Number=Math.floor(seconds/(3600));
		    var m:Number=Math.floor(seconds/60)%60;
		    var s:Number=Math.floor(seconds)%60
			str=h + '小时' + m + '分' + s+ '秒';
			return str;
			
		}
	}
	
}